package posecco.server;

import java.util.ArrayList;

import posecco.client.User;
import posecco.client.UserListService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class UserListServiceImpl extends RemoteServiceServlet implements
		UserListService {

	public ArrayList<User> getUserList() throws IllegalArgumentException {
		// Verify that the input is valid. 
		try {
			ObjectifyService.register(User.class);
		}
		catch (IllegalArgumentException e) {}
		ArrayList<User> users = new ArrayList<User>();
        Objectify ofy = ObjectifyService.begin();
        Query<User> query = ofy.query(User.class);
        try {
        	
    		for (User fetched : query) {
    			
    			users.add(fetched);
    		}
    		return users;
        }
        catch (NullPointerException e) {
        	
        	return null;
        }
	}
}
